package sort

import "fmt"

var cnt int

func quickSort(nums []int) {
	merge(nums, 0, len(nums)-1)
}

func merge(nums []int, low, high int) {
	if low < high {
		cnt++
		fmt.Println(cnt)
		var left = low
		var right = high
		var pvoit = nums[left]
		for left < right {
			for left < right && nums[right] > pvoit {
				right--
			}
			if left < right {
				nums[left] = nums[right]
				left++
			}
			for left < right && nums[left] < pvoit {
				left++
			}
			if left < right {
				nums[right] = nums[left]
				right--
			}
		}
		nums[left] = pvoit
		merge(nums, low, left-1)
		merge(nums, left+1, high)
	}
}
